//
//  JDRequest.m
//  Jared_AFN_Cache
//
//  Created by Jared on 2017/1/19.
//  Copyright © 2017年 Jared. All rights reserved.
//

#import "JDRequest.h"
#import "InterfaceResultParser.h"

@implementation JDRequest

- (void)getDataWithParams:(NSDictionary *)params withDataBlock:(sendBlock)sendBlock{
    JD_AFNetworking *afn = [[JD_AFNetworking alloc] init];
    
}

-(void)requestDataWithURL:(NSString *)url params:(NSDictionary *)params success:(void (^)(CommonResponseBody *))sucess failure:(void (^)(CommonResponseBean *))failure{
    JD_AFNetworking *afn = [[JD_AFNetworking alloc] init];
    [afn requestWithURL:url withParams:params withCacheType:JDCacheTypeReturnCacheDataThenLoad withRequestType:NetworkGetType withResult:^(id responseObject, NSError *error) {
        NSLog(@"responseObject==---===%@", responseObject);
        [self handleSuccessWithURL:url responseObject:responseObject success:sucess failure:failure];
    }];
}

- (void)requestListDataWithURL:(NSString *)url params:(NSDictionary *)params cacheType:(JDCacheType)cacheType success:(void (^)(CommonResponseBody *))sucess failure:(void (^)(CommonResponseBean *))failure{
    JD_AFNetworking *afn = [[JD_AFNetworking alloc] init];
    [afn requestWithURL:url withParams:params withCacheType:cacheType withRequestType:NetworkGetType withResult:^(id responseObject, NSError *error) {
        
    }];
}


- (void)handleSuccessWithURL:(NSString *)url responseObject:(id)responseObject success:(void(^)(CommonResponseBody *responseBody))success failure:(void(^)(CommonResponseBean *responseBean))failure{
    CommonResponseBody *responseBody = [InterfaceResultParser getResponseBodyWithListDataFromJson:url header:nil resultJson:responseObject];
    NSLog(@"handle===%@", responseObject);
    if (responseObject) {
        NSString *resultCode = responseBody.responseBean.code;
        if (success) {
            success(responseBody);
        }
//        if ([resultCode isEqualToString:@"200"]) {
//            if (success) {
//                success(responseBody);
//            }
//        }else{
//            if (failure) {
//                failure(responseBody.responseBean);
//            }
//        }
        return;
    }
}


@end
